import os
from enum import IntEnum, unique


class Const:
    ENV = os.getenv('ENV', 'LOCAL').lower()
    # 项目名
    CI_PROJECT_NAMESPACE = os.getenv('CI_PROJECT_NAMESPACE')
    # 组名
    CI_APP_NAME = os.getenv('CI_APP_NAME')
    # sentry
    SENTRY_DSN = os.getenv('SENTRY_DSN')
    # jwt secret
    JWT_SECRET = os.getenv('JWT_SECRET')
    # request url
    MASS_TEXT_URL = 'https://prod.pandateacher.com/open-weixin/open-gateway/api/mass/text'


class RedisConst:
    REDIS_HOST = os.getenv('REDIS_HOST')
    REDIS_PASSWORD = os.getenv('REDIS_PASSWORD')
    REDIS_PORT = 6379
    REDIS_PREFIX = os.getenv('REDIS_PREFIX', Const.CI_APP_NAME)
    REDIS_DB = 0
    BROKER_URL = 'redis://{}:{}/{}'.format(REDIS_HOST, REDIS_PORT, 0)


class RabbitMqConst:
    RABBITMQ_HOST = os.getenv('RABBITMQ_HOST')
    RABBITMQ_USER = os.getenv('RABBITMQ_USER')
    RABBITMQ_PASSWORD = os.getenv('RABBITMQ_PASSWORD')
    RABBITMQ_VISUAL_HOST = os.getenv('RABBITMQ_VISUAL_HOST', '/')
    RABBITMQ_PORT = 5672

    RABBITMQ_BROKER_URL = 'amqp://{user}:{password}@{host}:{port}/{visual_host}'.format(
        user=RABBITMQ_USER,
        password=RABBITMQ_PASSWORD,
        host=RABBITMQ_HOST,
        port=RABBITMQ_PORT,
        visual_host=RABBITMQ_VISUAL_HOST,
    )


class DataBaseConst:
    FOR_OS = 'for_os'
    NINTH_STUDIO = 'ninth_studio'
    SILO = 'silo'
    if Const.ENV == 'prod':
        FOR_APIS = 'for_apis'
    else:
        FOR_APIS = 'for_apis_test'


@unique
class ResponseCodeEnum(IntEnum):
    """http response code"""

    # custom
    ZERO = 0

    # 1xx
    CONTINUE = 100
    SWITCHING_PROTOCOL = 102

    # 2xx
    OK = 200
    CREATED = 201
    ACCEPTED = 202
    NOT_CONTENT = 204

    # 4xx
    BAD_REQUEST = 400
    UNAUTHORIZED = 401
    FORBIDDEN = 403
    NOT_FOUND = 404

    # 5XX
    INTERNAL_SERVER_ERROR = 500
    BAD_GATEWAY = 502
    SERVICE_UNAVAILABLE = 503
